package web;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 演示ServletContext功能一： 获取全局初始化参数
 */
@WebServlet("/demo3")
public class ServletDemo3 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = getServletContext();

        /*
            获取项目运行过程中的码表 （写代码时不知道，需要后期运行项目时配置）
                ① 怎么配置
                    web项目可以通过web.xml配置全局参数 (springmvc采用的配置方式)
                            <context-param>
                                <param-name>encoding</param-name>
                                <param-value>UTF-8</param-value>
                            </context-param>
                ② 怎么获取
                    通过ServletContext获取web.xml中配置的全局参数
         */
//        String mb = "UTF-8";
        String mb = servletContext.getInitParameter("encoding");

        System.out.println(mb);
    }
}
